@using BTCPayServer.Components.StoreSelector
@using BTCPayServer.Components.MainNav
@inject Microsoft.AspNetCore.Http.IHttpContextAccessor _context;
@inject BTCPayServer.Services.BTCPayServerEnvironment _env
@inject SignInManager<ApplicationUser> _signInManager
@inject UserManager<ApplicationUser> _userManager

@{
    var user = await _userManager.GetUserAsync(User);
    var notificationDisabled = user?.DisabledNotifications == "all";
	var expectedScheme = _context.HttpContext.Request.Scheme;
	var expectedHost = _context.HttpContext.Request.Host.ToString().ToLower();
}

<!DOCTYPE html>
<html lang="en"@(_env.IsDeveloping ? " data-devenv" : "")>
<head>
    <partial name="LayoutHead" />
    @await RenderSectionAsync("PageHeadContent", false)
</head>
<body class="d-flex flex-column flex-lg-row min-vh-100">
<header id="mainMenu" class="btcpay-header d-flex flex-column d-print-none" v-pre>
    <div id="mainMenuHead">
        <button id="mainMenuToggle" class="mainMenuButton" type="button" data-bs-toggle="offcanvas" data-bs-target="#mainNav" aria-controls="mainNav" aria-expanded="false" aria-label="Toggle navigation">
            <span>Menu</span>
        </button>
        <vc:store-selector />
        @if (_signInManager.IsSignedIn(User))
        {
			<component type="typeof(BTCPayServer.Blazor.NotificationsDropDown)" render-mode="ServerPrerendered" />
        }
    </div>
    <vc:main-nav />
</header>
<template id="badUrl">
	<div class="alert alert-danger alert-dismissible m-3" role="alert">
        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="@StringLocalizer["Close"]">
            <vc:icon symbol="close"/>
        </button>
        <span html-translate="true">BTCPay is expecting you to access this website from <strong>@(expectedScheme)://@(expectedHost)/</strong>. If you use a reverse proxy, please set the <strong>X-Forwarded-Proto</strong> header to <strong id="browserScheme">@(expectedScheme)</strong></span>
        (<a href="https://docs.btcpayserver.org/FAQ/Deployment/#cause-3-btcpay-is-expecting-you-to-access-this-website-from" target="_blank" class="alert-link" rel="noreferrer noopener" text-translate="true">More information</a>)
    </div>
</template>
<main id="mainContent">
    @if (!_env.IsSecure(_context.HttpContext))
    {
        <div id="insecureEnv" class="alert alert-danger alert-dismissible" style="position:absolute; top:75px;" role="alert">
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="@StringLocalizer["Close"]">
                <vc:icon symbol="close"/>
            </button>
            <span text-translate="true">Your access to BTCPay Server is over an unsecured network. If you are using the docker deployment method with NGINX and HTTPS is not available, you probably did not configure your DNS settings correctly. We disabled the register and login link so you don't leak your credentials.</span>
        </div>
    }
    <section>
        @RenderBody()
    </section>
    
    <partial name="_Footer"/>
    <partial name="LayoutFoot"/>

    @await RenderSectionAsync("PageFootContent", false)
    <partial name="LayoutPartials/SyncModal"/>

    @if (!notificationDisabled)
    {
        <script>
			var mainContent = document.getElementById("mainContent");
			if (window.location.protocol != "@(expectedScheme):" || window.location.host.toLowerCase() != "@expectedHost")
			{
				var tmpl = document.getElementById("badUrl");
				mainContent.prepend(tmpl.content.cloneNode(true));
			}
        </script>
    }
</main>
</body>
</html>
